package com.example.rightmost.controller.admin;

import com.example.rightmost.entity.Piece;
import com.example.rightmost.entity.Result;
import com.example.rightmost.service.PieceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author:javayhch
 * @date:2024/8/20
 * @description:
 */

@RestController("adminPieceController")
@RequestMapping("/admin/piece")
public class PieceController {

    @Autowired
    public PieceService pieceService;

    //获取所有动态
    @RequestMapping("/getPieceList")
    public PageInfo getPieceList(@RequestParam(defaultValue = "1") int page,
                                 @RequestParam(defaultValue = "5") int size,
                                 @RequestParam String userName,
                                 @RequestParam String topicName,
                                 @RequestParam String text
                                 ){
        PageHelper.startPage(page, size);
        List<Piece> list = pieceService.getPieceList(text, userName, topicName);
        PageInfo<Piece> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("/getUserNameMap")
    public Result getUserNameMap(){
        return pieceService.getUserNameMap();
    }

    @RequestMapping("/getTopicNameMap")
    public Result getTopicNameMap(){
        return pieceService.getTopicNameMap();
    }

}
